﻿using Avalonia.BiliBili.Libs.Models;
using Bilibili.Common.Log;
using Bilibili.Model.Dynamic;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Avalonia.BiliBili.Views.ChildViews.Dynamic
{
    public sealed class DynamicItemViewModel : ReactiveObject, IDisposable
    {
        private ObservableCollection<DynamicItemCard> cards = [];
        public ObservableCollection<DynamicItemCard> Cards
        {
            get => cards;
            set => this.RaiseAndSetIfChanged(ref cards, value);
        }
        public void AddCards(List<DynamicCards> cards)
        {
            try
            {
                foreach (var card in cards)
                {
                    var dynamicItem = new DynamicItemCard(card);
                    Cards.Add(dynamicItem);
                }
            }
            catch (Exception ex)
            {
                LogManager.Instance.LogError("AddCards", ex);
            }
        }
        public void ClearCards()
        {
            try
            {
                Cards.Clear();
            }
            catch { }
        }
        public void Dispose()
        {
            try
            {
                cards.Clear();
            }
            catch { }
        }
    }
}